// Copyright 2010 - eggsy _at_ eggsylife.co.uk
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package uk.co.eggsylife;

import uk.co.eggsylife.async.activity.AsyncHandlingActivity;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.widget.Toast;

public class AsyncAndroidMainActivity extends Activity implements AsyncHandlingActivity{
    
	/** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        // Execute Twitter User search task by hitting the Twitter API
        new TwitterUserInfoAsyncTask(this).execute("http://api.twitter.com/1/users/show.json", "earlybird");
    }

	@Override
	public void handleAsynchronousResponse(Object response) {
		TwitterUserModeltem twitterUserModelItem = (TwitterUserModeltem)response;
		
		// Perform a Toast popup to show Twitter details
		Context context = getApplicationContext();
		
		String toastText = "User: " + twitterUserModelItem.getScreen_name() + 
						   "\nLocation: " + twitterUserModelItem.getLocation() + 
						   "\nFriends count: " + twitterUserModelItem.getFriends_count();

		Toast.makeText(context, toastText, Toast.LENGTH_LONG).show();
	}
}